package com.mxpio.erp.common.equipment.entity;

import com.mxpio.erp.common.enums.CommonEnums;
import com.mxpioframework.jpa.annotation.Generator;
import com.mxpioframework.jpa.policy.impl.UUIDPolicy;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.BaseEntity;
import com.mxpioframework.system.entity.TreeAble;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.util.List;


/**
 * 设备分类对象 EQUIPMENT_CATEGORY
 * 
 * @author Cheng
 * @date 2023-06-26
 */
@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "MB_ERP_EQUIPMENT_CATEGORY")
@Schema(description="设备分类")
public class EquipmentCategory extends BaseEntity implements TreeAble<EquipmentCategory> {

private static final long serialVersionUID=1L;


    @Id
    @Generator(policy = UUIDPolicy.class)
    @Column(name = "ID_")
    @Schema(description = "主键")
    private String id;

    @Column(name = "NAME_")
    @Schema(description = "分类名称")
    private String name;

    @Column(name = "CODE_")
    @Schema(description = "分类编码")
    private String code;

    @Column(name = "IS_ENABLE_")
    @Schema(description = "是否启用")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private Integer isEnable;

    @Column(name = "REMARKS_")
    @Schema(description = "备注")
    private String remarks;

    @Column(name = "PID_")
    @Schema(description = "父级节点")
    private String pid;

    @Column(name = "HAS_CHILD_")
    @Schema(description = "是否有子节点")
    private Boolean hasChild;

    @Column(name = "TENANT_")
    @Schema(description = "租户")
    private String tenant;

    @Transient
    private List<EquipmentCategory> children;

    @Override
    public List<EquipmentCategory> getTreeChildren() {
        return children;
    }

    @Override
    public String getCurrentNodeKey() {
        return id;
    }

    @Override
    public String getParentNodeKey() {
        return CommonEnums.YesNo.NO.getCode().equals(pid) ? null : pid;
    }

    @Override
    public void setTreeChildren(List<EquipmentCategory> children) {
        this.children = children;
    }

}
